var app=getApp()
Page({
  data: {
    rembNum:0,
    data_index:0,
    number:0,
    reviewNum:0,
    recite:[],
    // changeDays:0,
    list:[
      {title:"专业模式",info:"认识中药"},
      {title:"趣味模式",info:"玩味中药"}
    ]
  },
  onLoad: function (options) {
    let that=this
    // let changeDays=that.data.changeDays
    console.log(app.globalData.changeDays)
    let recite=that.data.recite
    wx.cloud.database().collection("userList").where({openid:wx.getStorageSync('openid')}).get({
      success(res){
        recite=res.data[0].recite
        // that.data.index=0
        that.data.data_index=Number(recite[0].data_index)
        that.data.number=Number(recite[0].data_index)+Number(options.rembNum)
        that.data.rembNum=Number(options.rembNum)
        that.data.pre_index=Number(recite[0].pre_index)
        if(changeDays){
          that.data.reviewNum=Number(recite[0].data_index)-Number(recite[0].pre_index)
        }else{
          that.data.reviewNum=0;
        }
      }
    })
  },
  toTestPage: function (e) {
    let that=this
    console.log(e)
    if(!app.globalData.changeDays)
    {
      console.log(e)
      if(e.currentTarget.dataset.testid=="趣味模式"){
        wx.redirectTo({
          url: '../recite_tcm_copy/recite_tcm?rembNum='+that.data.rembNum+'&number='+that.data.number+'&data_index='+that.data.data_index,
        })
      }else{
        wx.showModal({
          title: '提示',
          content: '今日任务已完成 继续学习吗',
          success: function (res) {
            if (res.confirm) {//这里是点击了确定以后
              console.log('用户点击确定')
              // that.data.data_index=Number(that.data.data_index)
              // that.data.number=Number(that.data.data_index)+Number(that.data.rembNum)
              wx.redirectTo({
                url: '../recite_tcm/recite_tcm?rembNum='+that.data.rembNum+'&index='+that.data.index+'&number='+that.data.number+'&data_index='+that.data.data_index+"&reviewNum="+that.data.reviewNum+'&pre_index='+that.data.pre_index
                // +'&testId=' + testId
              })
            } else {
              console.log('用户点击取消')
            }
          }
        })
      }
    }
    else
    {
      if(e.currentTarget.dataset.testid=="趣味模式"){
        wx.redirectTo({
          url: '../recite_tcm_copy/recite_tcm?rembNum='+that.data.rembNum+'&index='+that.data.index+'&number='+that.data.number+'&data_index='+that.data.data_index+"&reviewNum="+that.data.reviewNum,
        })
      }else{
        wx.redirectTo({
          url: '../recite_tcm/recite_tcm?rembNum='+that.data.rembNum+'&index='+that.data.index+'&number='+that.data.number+'&data_index='+that.data.data_index+"&reviewNum="+that.data.reviewNum+'&pre_index='+that.data.pre_index
          // +'&testId=' + testId
        })
      } 
    }
  }
})